#! /usr/bin/env python
# coding:utf-8
'''
本模块是为了实现修改学生成绩
'''
from function import cursor,db
def rev_grade():
    while True:
        try:
            stu_num = input('请输入你要修改成绩的学号：')
            if_id = cursor.execute('SELECT id FROM studata WHERE id=%d' % stu_num)
            if if_id:
                score = input('请输入该学生语文，数字和英语的成绩，用逗号隔开：')
                chinese, math, english = score
                if (0 <= chinese <= 100) and (0 <= math <= 100) and (0 <= english <= 100):
                    my_grade = 'UPDATE studata SET chinese=%d, math=%d, english=%d WHERE id=%d' \
                               % (chinese, math, english, stu_num)
                    cursor.execute(my_grade)
                    db.commit()
                    print '修改成功！！！'
                    break
            else:
                print '学号不存在，请输入正确的学号！！'
            select = input('继续请按1，返回请按0：')
            if select == 0:
                 break
        except (TypeError,EOFError, NameError,IOError, SyntaxError, ValueError):
            print '成绩或输入格式错误，请重新输入！！'
